package cn.stu.system.controller;


import cn.stu.common.utils.ApiData;
import cn.stu.framework.dto.DeptDto;
import cn.stu.framework.dto.DeptPageDto;
import cn.stu.framework.service.DeptService;
import cn.stu.system.annotation.LogAnnotation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 科室控制员
 *
 * @author 郑志豪
 * @date 2023/09/18
 */
@RestController
@RequestMapping("/dept")
public class DeptController {

    /**
     * 部门服务
     */
    @Autowired
    private DeptService deptService;


    /**
     * 选择部门
     *
     * @param deptPageDto 部门页面Dto
     * @return {@link ApiData}
     */
    @RequestMapping(value = "/selectDept", method = RequestMethod.GET)
    public ApiData selectDept(DeptPageDto deptPageDto) {
        return deptService.selectDept(deptPageDto);
    }

    /**
     * 删除部门
     *
     * @param deptId 部门ID
     * @return {@link ApiData}
     */
    @LogAnnotation("删除部门")
    @RequestMapping(value = "/deleteDept", method = RequestMethod.DELETE)
    public ApiData deleteDept(@RequestParam("deptId") Long deptId) {
        return deptService.deleteDept(deptId);
    }


    /**
     * 插入部门
     *
     * @param deptDto 部门Dto
     * @return {@link ApiData}
     */
    @LogAnnotation("新增部门")
    @RequestMapping(value = "/insertDept", method = RequestMethod.POST)
    public ApiData insertDept(@RequestBody @Valid DeptDto deptDto) {
        return deptService.insertDept(deptDto);
    }


    /**
     * 更新部门
     *
     * @param deptDto 部门Dto
     * @return {@link ApiData}
     */
    @LogAnnotation("更新部门")
    @RequestMapping(value = "/updateDept", method = RequestMethod.PUT)
    public ApiData updateDept(@RequestBody @Valid DeptDto deptDto) {
        return deptService.updateDept(deptDto);
    }
}

